//
// Created by Dell on 2021/12/5.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int n,m;
map<int,bool>Map;
map<int,bool>Map2;
int main(){
    vector<int>a,ans1,ans2,ans3;
    cin>>n;
    for(int i = 0;i<n;++i){
        int tem = 0;
        cin>>tem;
        Map[tem] = 1;
        ans2.push_back(tem);
        a.push_back(tem);
    }
    cin>>m;
    for(int i = 0;i<m;++i){
        int tem;
        cin>>tem;
        if(Map.find(tem)!=Map.end()){
            ans1.push_back(tem);
        }else{
            ans2.push_back(tem);
        }
        Map2[tem] = 1;
    }
    for(int i = 0;i<a.size();++i){
        int c = a[i];
        if(Map2.find(c) == Map2.end()){
            ans3.push_back(c);
        }
    }

    sort(ans1.begin(),ans1.end());
    sort(ans2.begin(),ans2.end());    sort(ans3.begin(),ans3.end());
    for(int i = 0;i<ans1.size();++i){
        int c = ans1[i];
        cout<<c<<" ";
    }
    cout<<endl;
    for(int i = 0;i<ans2.size();++i){
       int c = ans2[i];
        cout<<c<<" ";
    }
    cout<<endl; for(int i = 0;i<ans3.size();++i){
       int  c = ans3[i];
        cout<<c<<" ";
    }
    cout<<endl;

    return 0;
}